/*
 * Created by SharpDevelop.
 * User: Guy Fomi
 * Date: 2/6/2011
 * Time: 2:14 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;
using System.Collections;
using System.Collections.Generic;
using HtmlAgilityPack;
using System.Web.Script.Serialization;

namespace TomatoSynchronizer.Store
{
	/// <summary>
	/// Description of ConfigurationStore.
	/// </summary>
	public class ConfigurationStore
	{
		private Site _site;
		private HtmlWeb _client;
		
		public ConfigurationStore(Site site,HtmlWeb client)
		{
			_site = site;
			_client = client;
		}
		
		public IDictionary GetConfiguration()
		{
			List<IDictionary> entries = new List<IDictionary>();
			
			HtmlDocument doc = _client.Load(_site.Url + "/admin/json.php?action=load_cards_information&module=configuration_wizard");
			HtmlNode node = doc.DocumentNode.SelectSingleNode("/");
			
			JavaScriptSerializer serialiser = new JavaScriptSerializer();
			IDictionary json = serialiser.Deserialize<IDictionary>(node.InnerText);
			foreach(string key in json.Keys)
			{
				if(key == "data")
				{					
					IDictionary Configuration = (IDictionary)json[key];					
					entries.Add(Configuration);
				}
			}			
			
			return entries[0];
		}		
	}
}
